package com.example.test.dialogfactory;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
import easier.recycler.BaseViewHolder;
import easier.recycler.MultiTypeAdapter;
import easier.recycler.TypeViewHolder;
import java.util.ArrayList;
import java.util.List;

public class MainActivity118 extends AppCompatActivity {

    private RecyclerView recycler;
    private EditText edit;

    public static void start( Context context ) {

        Intent starter = new Intent( context, MainActivity118.class );
        context.startActivity( starter );
    }

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main118 );
        initView();
    }

    private void initView() {

        recycler = (RecyclerView) findViewById( R.id.recycler );
        edit = (EditText) findViewById( R.id.edit );

        recycler.setLayoutManager( new LinearLayoutManager( this ) );
        recycler.setAdapter( new MultiTypeAdapter( convert() ) );
    }

    private List< TypeViewHolder > convert() {

        ArrayList< TypeViewHolder > list = new ArrayList<>();
        for ( int i = 0; i < 100; i++ ) {
            list.add( build() );
        }
        return list;
    }

    private TypeViewHolder build() {

        return new BaseViewHolder( R.layout.recycler_item_00 ) {
            @Override
            protected void onBind( ViewHolder viewHolder, View root, int position, int type, @NonNull List< Object > payloads ) {

                super.onBind( viewHolder, root, position, type, payloads );
                ((TextView) root.findViewById( R.id.text )).setText( "item " + position );
            }
        };
    }
}